package com.eascs.web.o2o.report.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.common.util.StopWatch;
import com.eascs.web.o2o.report.service.ProcessMonitorReportService;
import com.eascs.web.o2o.report.service.DayReprotDataService;
import com.eascs.web.o2o.report.service.SynoInfoReportService;
import com.eascs.web.sso.UserHolder;

@Component("taskReportJob")
public class DayReportTask {
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	DayReprotDataService dayService;
	@Autowired
	ProcessMonitorReportService processMonitorReportService;
	@Autowired
	SynoInfoReportService synoInfoService;


	/**
	 * 管理层日报表 （数据来源：service）
	 */
	@Scheduled(cron = "0 15 08 * * ?")
	public void job_day1() {
		logger.info("管理层日报表 （数据来源：service）,8点15分,生成管理层日报表 任务开始");
		StopWatch stopWatch = new StopWatch();
		dayService.adapter_day_service();
		logger.info("管理层日报表 （数据来源：service）,8点15分,生成日报表任务结束，共耗时：[{}]分", stopWatch.elapsedTime() / 1000 / 60);
	}

	// 数据发送来源于Service
	@Scheduled(cron = "0 30 08 * * ?")
	public void job_sendMail1() {
		logger.info("8点30分,发送管理层日报表邮件,任务开始(service)");
		StopWatch stopWatch = new StopWatch();
		if (synoInfoService.query()) {
			dayService.job_sendMail_service();
		} else {
			dayService.sendMail_our_service();
		}
		logger.info("8点30分,发送管理层日报表邮件,任务结束(service)，共耗时：[{}]分", stopWatch.elapsedTime() / 1000 / 60);
	}

	
	/**
	 * 管理层日报表 （数据来源：service）
	 */
	//@Scheduled(cron = "0 25 08 * * ?")
	public void asset_structure_report() {
		logger.info("新日邮件（资产结构本金日报和合作银行放款台账-新模板）（数据来源：service）,6点25分,生成资产结构本金日报任务开始");
		StopWatch stopWatch = new StopWatch();
		dayService.ass_adapter_day_service();
		dayService.rerundBankReportByNew();
		logger.info("新日邮件（资产结构本金日报和合作银行放款台账-新模板）（数据来源：service）,6点25分,生成资产结构本金日报任务结束，共耗时：[{}]分", stopWatch.elapsedTime() / 1000 / 60);
	}
	
	// 数据发送来源于Service
	//@Scheduled(cron = "0 40 08 * * ?")
	public void asset_structure_sendMail() {
		logger.info("8点40分,发送发送新日邮件（资产结构本金日报和合作银行放款台账-新模板）邮件,任务开始(service)");
		StopWatch stopWatch = new StopWatch();
		dayService.asset_sendMail_service();
		logger.info("发送发送新日邮件（资产结构本金日报和合作银行放款台账-新模板）邮件,任务结束(service)，共耗时：[{}]分", stopWatch.elapsedTime() / 1000 / 60);
	}
	
	
	
	
	// 管理层日报二期-省区流程监控表
	@Scheduled(cron = "0 20 07 * * ?")
	public void processMonitorReport() {
		logger.info("7点20分,生成省区流程监控表任务开始");
		StopWatch stopWatch = new StopWatch();
        processMonitorReportService.processMonitorReport();      
        logger.info("生成省区流程监控表任务结束，共耗时：[]分" , stopWatch.elapsedTime() / 1000 / 60);	
    }

	/*// 管理层日报二期-省区流程监控表发送
	@Scheduled(cron = "0 30 07 * * ?")
	public void processMonitorendEmial() {
		logger.info("7点30分,省区流程监控表邮件入库任务开始......");
		StopWatch stopWatch = new StopWatch();
		processMonitorReportService.process_sendMail();
		logger.info("7点30分,省区流程监控表邮件入库任务结束，共耗时：[]分",stopWatch.elapsedTime() / 1000 / 60);	
	}*/

}
